import { createStore } from 'vuex'
import axios from 'axios'
export default createStore({
  state: {
    token: ''
  },
  // 计算属性
  getters: {},
  // 处理同步逻辑
  mutations: {},
  //处理异步逻辑
  // 用来请求接口，处理异步数据
  actions: {
    // 请求登录接口
    // async返回的是一个promise
    async fetch_login({ commit }) {
      try {
        const response = await axios.post('http://localhost:7001/api/login')
        console.log('response:', response.data)

        return { code: 200, msg: 'success', data: response.data }
      } catch (error) {
        return { code: 500, msg: 'fail' }
      }
    }
  },
  modules: {}
})
